﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:view="clr-namespace:SqlExport.View"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:viewModel="clr-namespace:SqlExport.ViewModel" 
        xmlns:sampleData="clr-namespace:SqlExport.SampleData" xmlns:seui="clr-namespace:SqlExport"
        mc:Ignorable="d"
        x:Class="SqlExport.MainWindow"
        Title="{Binding Title}" 
        Icon="/SQLExport;component/SqlExport.ico"
        d:DesignWidth="525" d:DesignHeight="350" 
        d:DataContext="{d:DesignInstance sampleData:SampleMainWindowViewModel, IsDesignTimeCreatable=True}"
        DataContext="{Binding MainWindowViewModel, Source={StaticResource Locator}}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <view:MainMenu />
        <ToolBar Grid.Row="1">
            <Button x:Name="NewButton" Command="{Binding ApplicationCommands.NewQueryCommand}">
                <Button.Resources>
                    <ContextMenu x:Key="TemplatesMenu" ItemsSource="{Binding Templates}" StaysOpen="False" Opened="ContextMenu_Opened">
                        <ContextMenu.Resources>
                            <Style TargetType="{x:Type MenuItem}">
                                <Setter Property="Command" Value="{Binding Command}"/>
                                <Setter Property="CommandParameter" Value="{Binding Template}"/>
                            </Style>
                        </ContextMenu.Resources>
                        <ContextMenu.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding Templates}">
                                <TextBlock Text="{Binding Name}"/>
                            </HierarchicalDataTemplate>
                        </ContextMenu.ItemTemplate>
                    </ContextMenu>
                </Button.Resources>
                <StaticResource ResourceKey="NewDocumentIcon"/>
            </Button>
            <Button VerticalAlignment="Stretch" Click="NewButton_Opened">
                <Path Data="M 0 0 L 4 4 L 8 0 Z" Fill="#FF000000" />
            </Button>
            <Button x:Name="OpenButton" Content="{StaticResource OpenIcon}" Command="{Binding ApplicationCommands.OpenQueryCommand}"/>
            <Button x:Name="SaveButton" Content="{StaticResource SaveIcon}" Command="{Binding ApplicationCommands.SaveQueryCommand}"/>
            <Button x:Name="CloseButton" Content="{StaticResource CloseIcon}" Command="{Binding ApplicationCommands.CloseQueryCommand}"/>
            <Border Style="{StaticResource SeparatorStyle}"/>
            <Button x:Name="RunButton" Content="{StaticResource RunIcon}" Command="{Binding ApplicationCommands.RunQueryCommand}" />
            <Button x:Name="StopButton" Content="{StaticResource StopIcon}" Command="{Binding ApplicationCommands.StopQueryCommand}"/>
            <Border Style="{StaticResource SeparatorStyle}"/>
            <Button x:Name="ExportButton" Content="{StaticResource ExportIcon}" Command="{Binding ApplicationCommands.ExportResultsCommand}"/>
            <Border Style="{StaticResource SeparatorStyle}"/>
            <ComboBox ItemsSource="{Binding Databases}" SelectedItem="{Binding SelectedDatabase}" Style="{StaticResource DatabaseList}"/>
            <Button x:Name="SetConnectionButton" Content="{StaticResource ConnectIcon}" Command="{Binding ConnectCommand}"/>
        </ToolBar>
        <!--<View:QueryView Grid.Row="2" DataContext="{Binding SelectedQuery}" Text="{Binding AllText}" QueryText="{Binding QueryText, Mode=OneWayToSource}" />-->
        <TabControl x:Name="Queries" Grid.Row="2" SelectedItem="{Binding SelectedQuery}" ItemsSource="{Binding Queries}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <view:LabeledImage Content="{Binding DisplayText}" ImageSource="{Binding QueryStatusImage, Converter={StaticResource StringToResourceConverter}}" />
                        <seui:PathButton x:Name="PART_Close"
                                         DockPanel.Dock="Right" 
                                         ToolTip="Close Tab"
                                         EnabledFill="#FF969696"
                                         DisabledFill="#FF969696"
                                         PressedFill="#FF9D3838"
                                         Margin="3,0,-3,0"
                                         Command="{Binding DataContext.CloseQueryCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                                         CommandParameter="{Binding}"
                                         Path="F1 M 2,0.5 L 7,6 L 12,0.5 L 14,3 L 9,8 L 14,13 L 12,15 L 7,10 L 2,15 L 0,13 L 5,8 L 0,3 Z" />
                    </StackPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate DataType="{x:Type viewModel:QueryViewModel}">
                    <view:QueryView DataContext="{Binding}" />
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
        <!--<Ui:ScrollableTabControl x:Name="Queries" Grid.Row="2" SelectedItem="{Binding SelectedQuery}">
            <Ui:ScrollableTabControl.ItemContainerStyle>
                <Style TargetType="{x:Type Ui:CloseableTabItem}">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Ui:LabeledImage DataContext="{Binding DataContext,RelativeSource={RelativeSource AncestorType=Ui:CloseableTabItem}}"
                                                 ImageSource="{ViewModel:BindableStaticResource {Binding QueryStatusImage}}"
                                                 Content="{Binding DisplayText}"
                                                 ToolTip="{Binding Filename}"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Ui:ScrollableTabControl.ItemContainerStyle>
        </Ui:ScrollableTabControl>-->
    </Grid>
</Window>
    